/*     */ package com.yc.service;
/*     */ 
/*     */ import btsm.bean.sysPro;
/*     */ import com.yc.dao.FileDAO;
/*     */ import com.yc.dao.FolderBODAO;
/*     */ import com.yc.dao.model.FileBO;
/*     */ import com.yc.dao.model.FolderBO;
/*     */ import com.yc.util.ListContentsBFO;
/*     */ import com.yc.util.UtilBtsm;
/*     */ import java.io.File;
/*     */ import java.io.InputStream;
/*     */ import java.util.HashMap;
/*     */ import java.util.List;
/*     */ import java.util.Map;
/*     */ import java.util.Properties;
/*     */ import java.util.StringTokenizer;
/*     */ import org.apache.commons.logging.Log;
/*     */ import org.apache.commons.logging.LogFactory;
/*     */ 
/*     */ public class FolderService
/*     */ {
/*  25 */   private static final Log log = LogFactory.getLog(FolderService.class);
/*     */   private FolderBODAO folderDAO;
/*     */   private FileDAO fileDao;
/*  29 */   private String propertiesFileName = "/btsm.properties";
/*  30 */   private String uploadPath = "";
/*  31 */   private String uploadCommPath = "";
/*  32 */   private String tempPath = "";
/*     */ 
/*     */   public void setFolderDAO(FolderBODAO folderDAO) {
/*  35 */     this.folderDAO = folderDAO;
/*     */   }
/*     */ 
/*     */   public FolderService()
/*     */   {
/*  40 */     this.folderDAO = new FolderBODAO();
/*  41 */     this.fileDao = new FileDAO();
/*     */     try
/*     */     {
/*  44 */       Properties p = new Properties();
/*  45 */       InputStream in = FolderService.class.getResourceAsStream(this.propertiesFileName);
/*  46 */       p.load(in);
/*  47 */       in.close();
/*     */ 
/*  49 */       sysPro sPro = new sysPro();
/*  50 */       String strUploadPath = sPro.getUploadpath();
/*  51 */       if ((strUploadPath != null) && (!"".equalsIgnoreCase(strUploadPath)))
/*     */       {
/*  53 */         this.uploadPath = strUploadPath.replaceAll("//", "\\");
/*     */       }
/*  56 */       else if (p.containsKey("uploadPath")) {
/*  57 */         this.uploadPath = p.getProperty("uploadPath");
/*     */       }
/*     */ 
/*  60 */       String strUploadComm = "";
/*  61 */       if (this.uploadPath.endsWith("/"))
/*     */       {
/*  63 */         this.uploadPath = this.uploadPath.substring(0, this.uploadPath.length() - 1);
/*     */       }
/*  65 */       this.uploadCommPath = (this.uploadPath + "Comm");
/*  66 */       log.info("uploadCommPath = " + this.uploadCommPath);
/*  67 */       if (p.containsKey("tempPath")) {
/*  68 */         this.tempPath = p.getProperty("tempPath");
/*     */       }
/*     */ 
/*     */     }
/*     */     catch (Exception e)
/*     */     {
/*  74 */       e.printStackTrace();
/*     */     }
/*     */   }
/*     */ 
/*     */   private Map getFolderPath(String strParenFolderPath, String strUserID, String strFolderName)
/*     */   {
/*  80 */     Map map = new HashMap();
/*  81 */     StringBuffer buff = new StringBuffer();
/*  82 */     StringBuffer buffData = new StringBuffer();
/*  83 */     if (strParenFolderPath == null)
/*     */     {
/*  85 */       buff.append(this.uploadPath);
/*  86 */       StringTokenizer token = new StringTokenizer(this.uploadPath, "\\");
/*  87 */       while (token.hasMoreTokens())
/*     */       {
/*  89 */         buffData.append(token.nextToken());
/*  90 */         buffData.append("\\\\");
/*     */       }
/*     */ 
/*  93 */       buffData.append(strUserID);
/*  94 */       buffData.append("\\\\");
/*  95 */       buffData.append(strFolderName);
/*     */ 
/*  97 */       buff.append("\\");
/*  98 */       buff.append(strUserID);
/*  99 */       buff.append("\\");
/* 100 */       buff.append(strFolderName);
/*     */     }
/*     */     else
/*     */     {
/* 104 */       strParenFolderPath = strParenFolderPath.trim();
/* 105 */       StringTokenizer tokenP = new StringTokenizer(strParenFolderPath, "\\");
/*     */ 
/* 107 */       while (tokenP.hasMoreTokens())
/*     */       {
/* 109 */         String str = tokenP.nextToken();
/* 110 */         buffData.append(str);
/* 111 */         buff.append(str);
/* 112 */         buffData.append("\\\\");
/* 113 */         buff.append("\\");
/*     */       }
/* 115 */       buff.append(strFolderName);
/* 116 */       buffData.append(strFolderName);
/*     */     }
/*     */ 
/* 119 */     map.put("DATA", buffData.toString());
/* 120 */     map.put("PATH", buff.toString());
/* 121 */     return map;
/*     */   }
/*     */ 
/*     */   private Map getComFolderPath(String strParenFolderPath, String strFolderName)
/*     */   {
/* 128 */     Map map = new HashMap();
/* 129 */     StringBuffer buff = new StringBuffer();
/* 130 */     StringBuffer buffData = new StringBuffer();
/* 131 */     if (strParenFolderPath == null)
/*     */     {
/* 133 */       buff.append(this.uploadCommPath);
/* 134 */       StringTokenizer token = new StringTokenizer(this.uploadCommPath, "\\");
/* 135 */       while (token.hasMoreTokens())
/*     */       {
/* 137 */         buffData.append(token.nextToken());
/* 138 */         buffData.append("\\\\");
/*     */       }
/* 140 */       buffData.append(strFolderName);
/*     */ 
/* 142 */       buff.append("\\");
/* 143 */       buff.append(strFolderName);
/*     */     }
/*     */     else
/*     */     {
/* 147 */       strParenFolderPath = strParenFolderPath.trim();
/* 148 */       StringTokenizer tokenP = new StringTokenizer(strParenFolderPath, "\\");
/*     */ 
/* 150 */       while (tokenP.hasMoreTokens())
/*     */       {
/* 152 */         String str = tokenP.nextToken();
/* 153 */         buffData.append(str);
/* 154 */         buff.append(str);
/* 155 */         buffData.append("\\\\");
/* 156 */         buff.append("\\");
/*     */       }
/* 158 */       buff.append(strFolderName);
/* 159 */       buffData.append(strFolderName);
/*     */     }
/*     */ 
/* 162 */     map.put("DATA", buffData.toString());
/* 163 */     map.put("PATH", buff.toString());
/* 164 */     return map;
/*     */   }
/*     */ 
/*     */   public boolean createFolder(FolderBO folderBO)
/*     */   {
/* 176 */     boolean boolFlag = true;
/*     */     try
/*     */     {
/* 179 */       String strParenFolderPath = this.folderDAO.getFolderPath(folderBO.getParentId());
/* 180 */       Map map = getFolderPath(strParenFolderPath, folderBO.getUserId(), folderBO.getFolderName());
/* 181 */       UtilBtsm.createFolder(map.get("PATH").toString());
/* 182 */       folderBO.setOther1(map.get("DATA").toString());
/* 183 */       this.folderDAO.save(folderBO);
/*     */     }
/*     */     catch (Exception e) {
/* 186 */       e.printStackTrace();
/* 187 */       boolFlag = false;
/*     */     }
/*     */ 
/* 190 */     return boolFlag;
/*     */   }
/*     */ 
/*     */   public boolean createComFolder(FolderBO folderBO)
/*     */   {
/* 195 */     boolean boolFlag = true;
/*     */     try
/*     */     {
/* 198 */       String strParenFolderPath = this.folderDAO.getFolderPath(folderBO.getParentId());
/* 199 */       Map map = getComFolderPath(strParenFolderPath, folderBO.getFolderName());
/* 200 */       UtilBtsm.createFolder(map.get("PATH").toString());
/* 201 */       folderBO.setOther1(map.get("DATA").toString());
/* 202 */       this.folderDAO.save(folderBO);
/*     */     }
/*     */     catch (Exception e) {
/* 205 */       e.printStackTrace();
/* 206 */       boolFlag = false;
/*     */     }
/*     */ 
/* 209 */     return boolFlag;
/*     */   }
/*     */ 
/*     */   public boolean deleteFolder(String strFolderID)
/*     */   {
/* 222 */     boolean flag = true;
/*     */     try
/*     */     {
/* 225 */       String strFolderPath = this.folderDAO.getFolderPath(strFolderID);
/* 226 */       UtilBtsm.deleteFolder(strFolderPath);
/* 227 */       this.fileDao.deleteFileByPath(strFolderID);
/* 228 */       this.folderDAO.deleteFolder(strFolderID);
/*     */     }
/*     */     catch (Exception e) {
/* 231 */       flag = false;
/*     */     }
/* 233 */     return flag;
/*     */   }
/*     */ 
/*     */   public boolean updateFolderName(FolderBO bo)
/*     */   {
/* 242 */     return this.folderDAO.updateFolderName(bo);
/*     */   }
/*     */ 
/*     */   public String queryMaxFolderID()
/*     */   {
/* 251 */     return this.folderDAO.queryMaxFolderID();
/*     */   }
/*     */ 
/*     */   public List findByUserId(String userId, String strParentFolderID, String strDepth)
/*     */   {
/* 257 */     return this.folderDAO.findByUserId(userId, strParentFolderID, strDepth);
/*     */   }
/*     */ 
/*     */   public List findComFolder(String strParentFolderID)
/*     */   {
/* 263 */     return this.folderDAO.findComFolder(strParentFolderID);
/*     */   }
/*     */ 
/*     */   public ListContentsBFO getContents(Map condition)
/*     */   {
/* 273 */     return this.fileDao.getContents(condition);
/*     */   }
/*     */ 
/*     */   public ListContentsBFO getComContents(Map condition)
/*     */   {
/* 278 */     return this.fileDao.getComContents(condition);
/*     */   }
/*     */ 
/*     */   public boolean deleteFile(String strFileID)
/*     */   {
/* 288 */     String strFilePath = this.fileDao.getFilePath(strFileID);
/* 289 */     boolean boolFlag = this.fileDao.deleteFile(strFileID);
/*     */     try
/*     */     {
/* 292 */       log.info("delete [" + strFilePath + "] file.");
/* 293 */       File deleteFile = new File(strFilePath);
/* 294 */       if (deleteFile.exists())
/* 295 */         deleteFile.delete();
/*     */     }
/*     */     catch (Exception e) {
/* 298 */       e.printStackTrace();
/* 299 */       boolFlag = false;
/*     */     }
/* 301 */     return boolFlag;
/*     */   }
/*     */ 
/*     */   public boolean setFileShare(FileBO bo)
/*     */   {
/* 311 */     return this.fileDao.setFileShare(bo);
/*     */   }
/*     */ 
/*     */   public boolean isFile(String strFolderID, String strFileName)
/*     */   {
/* 316 */     boolean flag = true;
/*     */     try
/*     */     {
/* 319 */       String strName = strFileName.substring(strFileName.lastIndexOf("\\") + 1);
/* 320 */       String strFilePath = this.folderDAO.getFolderPath(strFolderID);
/* 321 */       StringTokenizer token = new StringTokenizer(strFilePath, "\\");
/* 322 */       StringBuffer buf = new StringBuffer();
/* 323 */       while (token.hasMoreTokens())
/*     */       {
/* 325 */         buf.append(token.nextToken());
/* 326 */         buf.append("\\");
/*     */       }
/* 328 */       buf.append(strName);
/* 329 */       log.debug(buf.toString());
/* 330 */       File file = new File(buf.toString());
/* 331 */       if (file.exists())
/* 332 */         flag = false;
/*     */     }
/*     */     catch (Exception e) {
/* 335 */       e.printStackTrace();
/* 336 */       flag = false;
/* 337 */       log.error(e.getMessage());
/*     */     }
/* 339 */     return flag;
/*     */   }
/*     */ 
/*     */   public boolean editFileName(FileBO bo)
/*     */   {
/* 344 */     boolean flag = true;
/*     */     try
/*     */     {
/* 347 */       String strNewFileName = bo.getFileName();
/* 348 */       String strFilePath = this.fileDao.getFilePath(bo.getFileId());
/* 349 */       log.info("strFilePath = " + strFilePath);
/* 350 */       log.info("strNewFileName = " + strNewFileName);
/* 351 */       StringTokenizer token = new StringTokenizer(strFilePath, "\\");
/* 352 */       String[] ary = new String[token.countTokens()];
/* 353 */       int count = 0;
/* 354 */       while (token.hasMoreTokens())
/*     */       {
/* 356 */         ary[(count++)] = token.nextToken();
/*     */       }
/* 358 */       Map map = getEditPath(ary, strNewFileName);
/* 359 */       File file = new File(strFilePath);
/* 360 */       file.renameTo(new File(map.get("PATH").toString()));
/* 361 */       bo.setFilePath(map.get("DATA").toString());
/* 362 */       this.fileDao.renameFileName(bo);
/*     */     }
/*     */     catch (Exception e) {
/* 365 */       flag = false;
/* 366 */       e.printStackTrace();
/*     */     }
/*     */ 
/* 369 */     return flag;
/*     */   }
/*     */ 
/*     */   private Map getEditPath(String[] ary, String strFilwNewName)
/*     */   {
/* 376 */     Map map = new HashMap();
/* 377 */     StringBuffer buff = new StringBuffer();
/* 378 */     StringBuffer buffData = new StringBuffer();
/* 379 */     for (int i = 0; i < ary.length - 1; i++)
/*     */     {
/* 381 */       buff.append(ary[i]);
/* 382 */       buffData.append(ary[i]);
/* 383 */       buff.append("\\");
/* 384 */       buffData.append("\\\\");
/*     */     }
/* 386 */     buff.append(strFilwNewName);
/* 387 */     buffData.append(strFilwNewName);
/* 388 */     map.put("DATA", buffData.toString());
/* 389 */     map.put("PATH", buff.toString());
/* 390 */     return map;
/*     */   }
/*     */ }

/* Location:           E:\java\apache-tomcat-6.0.36\webapps\btsm\WEB-INF\classes\
 * Qualified Name:     com.yc.service.FolderService
 * JD-Core Version:    0.6.2
 */